package com.qq.BFMRSE.DAO;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

public class userDAOImpl extends JdbcDaoSupport implements userDAO{

	public String getPwd(String userName) {
		String sql="select pwd from userInfo where userName=?";
		String pwd=getJdbcTemplate().queryForObject(sql, String.class,userName);
		return pwd;
	}

	public int addNewUser(String userName, String pwd, String email) {
		String sql="insert into userInfo values(?,?,?)";
		return getJdbcTemplate().update(sql, new Object[]{userName, pwd,email},new int[]{java.sql.Types.VARCHAR,java.sql.Types.VARCHAR,java.sql.Types.VARCHAR});
	}

	public boolean isUserExist(String userName) {
		String sql="select count(*) from userInfo where userName=?";
		int count=getJdbcTemplate().queryForInt(sql, new Object[]{userName}, new int[]{java.sql.Types.VARCHAR});
		if(count>0)
			return true;
		else
		   return false;
	}

	public int deleteUser(String userName) {
		String sql="delete from userInfo where userName=?";
		return getJdbcTemplate().update(sql, new Object[]{userName},new int[]{java.sql.Types.VARCHAR});
	}

}
